package org.zzz.controller;

import org.zzz.entity.Course;
import org.zzz.entity.vo.CourseShowVo;
import org.zzz.service.CourseService;
import org.zzz.service.impl.CourseServiceImpl;
import org.zzz.utils.Result;

import java.util.List;

/**
 * @Author ZZF
 * @Time 2021/04/20 22:57
 */
public class CourseController {
    private CourseService courseService = new CourseServiceImpl();

    /**
     * 获取所有课程信息
     * @return
     */
    public Result<List<Course>> listCourse(){
        List<Course> courses = courseService.listCourse();
        return !courses.isEmpty() ? Result.success("查询成功").data(courses) : Result.error("暂无数据");
    }

    /**
     * 根据课程号获取课程信息
     * @param id
     * @return
     */
    public Result<Course> getCourseById(String id){
        Course course = courseService.getCourseById(id);
        return course != null ? Result.success("查询成功").data(course) : Result.error("查无此课程");
    }

    /**
     * 根据课程名 cname/课程号 cid 查询课程信息展示
     * @param type
     * @param value
     * @return
     */
    public Result<CourseShowVo> getCourseVoByIdOrName(String type,String value){
        CourseShowVo courseShowVo = courseService.getCourseShowVo(type, value);
        return courseShowVo != null ? Result.success("查询成功").data(courseShowVo) : Result.error("查无此课程");
    }

    /**
     * 添加课程
     * @param course
     * @return
     */
    public Result addCourse(Course course){
        return courseService.insertCourse(course) == true ? Result.success("添加成功") : Result.error("添加失败");
    }

    /**
     * 修改课程
     * @param course
     * @return
     */
    public Result updateCourse(Course course){
        return courseService.updateCourse(course) == true ? Result.success("修改成功") : Result.error("修改失败");
    }

    /**
     * 根据课程id删除课程
     * @param id
     * @return
     */
    public Result deleteCourse(String id){
        return courseService.deleteCourseById(id) == true ? Result.success("删除成功") : Result.error("删除失败");
    }

    /**
     * 获取所有课程信息展示
     * @return
     */
    public Result<List<CourseShowVo>> listCourseShowVo(){
        List<CourseShowVo> courseShowVos = courseService.listCourseShowVo();
        return courseShowVos != null ? Result.success("查询成功").data(courseShowVos) : Result.error("暂无数据");
    }
    
}
